<?php

/**
 * 每天3：50定时更新品牌流量池redis缓存
 */

error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('display_errors', 1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\cache\brand\FlowPool as brandFlowPool;
use Biz\model\bigData\BrandFlowPoolResult;
use Biz\model\brand\Brand as mBrand;

$day = date('Ymd', strtotime("-1 days"));
$result = BrandFlowPoolResult::select('*', ['day' => $day]);
$brandIds = array_column($result, 'brand_id');
$brandIds = array_unique(array_filter($brandIds));
$brandInfos = mBrand::getInfoByIds($brandIds);
$brandInfos = array_column($brandInfos, null, 'id');
foreach ($result as $row) {
    $brandInfo = isset($brandInfos[$row['brand_id']]) ? $brandInfos[$row['brand_id']] : [];
    $data = [
        'brand_id' => $row['brand_id'],
        'brand_type' => $row['brand_type'],
        'pack_type' => $brandInfo ? $brandInfo['pack_type'] : 0,
        'status' => $row['status']
    ];
    brandFlowPool::addData($row['brand_id'], $data);
}